<?php
// 获取传递的ID
$id = $_GET['id'];
include_once("./untils/conn.php");// 引入数据库连接配置文件



// $sql = "select * from list"; // 查询语句
// // $sql = "SELECT * FROM list WHERE id = $id";

// $result = mysqli_query($con, $sql); // 执行查询

// $row = mysqli_fetch_assoc($result);

// $zhutu = $row["zhutu"];

// $link = $row["link"];

// $goods =$row["name"]
    // echo "传回来的ID是：" . $id;

// 使用准备语句防止 SQL 注入攻击

// 查询与传递的id相匹配的数据
    $sql = "SELECT * FROM list WHERE id =".$id;
    $result = mysqli_query($con, $sql);
    
    
     if ($result->num_rows > 0) {
      // 输出数据
      while($row = $result->fetch_assoc()) {
        // 获取每个字段的值
        $zhutu = $row["zhutu"];
        $goods = $row["name"];
        $link = $row["link"];

        // 使用 <p> 标签渲染信息
        // echo "<p>主图: ".$zhutu."<br>名称: ".$name."<br>链接: ".$link."</p>";
      }
    } else {
    //   echo "未找到匹配的记录";
    }

    // $sql = "SELECT * FROM oder WHERE uid = $uid";
    // $result = mysqli_query($con, $sql);


?>


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>申请号卡</title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link rel="stylesheet" href="./other/index.css?v=2022" />
    <style>
		img {
			max-width: 100%;
			height: auto;
			display: block;
			margin: auto;
		}
	</style>
</head>

<body>
    <div id="app">
        <!--<van-nav-bar title="申请号卡">-->
        
        </van-nav-bar>
        <img src="<?php echo $zhutu; ?>" alt="">
        <van-divider style="font-size: 11px;color: #FF3333;float: left;">根据国家实名制要求，请准确提供申办人身份证信息。</van-divider>
        <van-form @submit="onSubmit">
            <van-field type="text" id="goods" name="goods" label="套餐名称" value="<?php echo $goods; ?>"></van-field>
            <van-field v-model="userinfo.username" name="username" label="姓名" placeholder="请输入姓名"></van-field>
            <van-field v-model="userinfo.useridno" name="useridno" label="身份证" placeholder="请输入身份证"></van-field>
            <van-field v-model="userinfo.phone" name="phone" label="电话" placeholder="请输入电话"></van-field>
            <!--<van-field v-model="userinfo.oidcard" name="oidcard" label="旧卡" placeholder="请输入旧卡"></van-field>-->
            <van-divider style="font-size: 11px;color: #FF3333;float: left;">请填写配送地址(支持全国配送，地址不详细不发货)</van-divider>
            <van-field readonly clickable name="distribution" :value="userinfo.distribution" label="配送地区"
                placeholder="请选择省市地区" @click="showArea = true"></van-field>
            <van-popup v-model="showArea" position="bottom">
                <van-area :area-list="areaList" :columns-placeholder="['请选择', '请选择', '请选择']" @confirm="onConfirm"
                    @cancel="showArea = false"></van-area>
            </van-popup>
            <van-field v-model="userinfo.address" name="address" label="详细地址" placeholder="街道/小区/门牌号"></van-field>

            <div style="margin: 16px;">
                <van-button round block type="info" :loading="disabled1" native-type="submit">
                    提交
                </van-button>
            </div>
        </van-form>
        <img src="<?php echo $link; ?>" alt="">
    </div>
</body>
	<script src="/vue/vue2.min.js"></script>
	<script src="/vue/vant2.min.js"></script>
<!-- 引入组件库 -->
<script src="/other/js/jquery.min.js"></script>
<script src="/other/js/jquery.cookie.js"></script>
<script src="/other/js/galogr.js?v=222"></script>
<script type="text/javascript">
    new Vue({
        el: '#app',
        filters: {
            ellipsis(value) {
                if (!value) return ''
                if (value.length > 8) {
                    return value.slice(0, 8) + '...'
                }
                return value
            },
            time: function time(value) {
                var now = new Date(value * 1000);
                y = now.getFullYear();
                m = now.getMonth() + 1;
                d = now.getDate();
                return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + now.toTimeString().substr(0, 8);
            },
            delcnes(value) {
                var reg = /[\u4E00-\u9FA5]/g;
                var result = value.replace(reg, '');
                return result;
            },
            originalprice(value) {
                return parseFloat(value) + 10;
            }
        },
        data() {
            return {
                disabled1: false,
                finished: false,
                refreshing: false,
                areaList: areaList, //配送地区
                showArea: false,//配送地区框是否显示
                userinfo: {
                    distribution: '',//配送地区
                    address: '',//详细地址
                    username: '',//用户姓名
                    useridno: '',//用户身份证
                    phone: '',//联系号码
                    // oidcard: ''//旧卡号码
                },
                distributionarea: {
                    province: [],//省
                    city: [],//市。
                    area: [],//区
                },//配送地址码
                addresslist: {},
            };
        },
        created() {

        },
        methods: {
            //返回
            onClickLeft() {
                window.history.go(-1)
            },
            //联系客服
            // onClickRight() {
            //     window.location.href = "../homepage/kefu.html";
            // },
            //校验表单
            validatefrom(values) {
                if (values.username == '' || values.username == null) {
                    this.$toast('请输入姓名');
                    return false;
                } else if (values.useridno == '' || values.useridno == null) {
                    this.$toast('请输入身份证号');
                    return false;
                } else if (this.verifyidcard(values.useridno) == false) {
                    return false;
                } else if (values.phone == '' || values.phone == null) {
                    this.$toast('请输入联系电话');
                    return false;
                } else if (this.checkphone(values.phone) == false) {
                    return false;
                } else if (values.distribution == '' || values.distribution == null) {
                    this.$toast('请选择配送地区');
                    return false;
                } else if (values.address == '' || values.address == null) {
                    this.$toast('请输入详细地址');
                    return false;
                } else {
                    return true;
                }
            },
            //校验联系电话
            checkphone(value) {
                const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
                if (value == '' || value == undefined || value == null) {
                    this.$toast('请输入电话号码');
                    return false;
                } else {
                    if ((!reg.test(value)) && value != '') {
                        this.$toast('请输入正确电话号码');
                        return false;
                    } else {
                        return true;
                    }
                }
            },
            //验证身份证号码
            verifyidcard(idCard) {
                var flag = false;
                //15位和18位身份证号码的正则表达式
                var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
                //如果通过该验证，说明身份证格式正确，但准确性还需计算
                if (regIdCard.test(idCard)) {
                    if (idCard.length == 18) {
                        var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); //将前17位加权因子保存在数组里
                        var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); //这是除以11后，可能产生的11位余数、验证码，也保存成数组
                        var idCardWiSum = 0; //用来保存前17位各自乖以加权因子后的总和
                        for (var i = 0; i < 17; i++) {
                            idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
                        }
                        var idCardMod = idCardWiSum % 11;//计算出校验码所在数组的位置
                        var idCardLast = idCard.substring(17);//得到最后一位身份证号码
                        //如果等于2，则说明校验码是10，身份证号码最后一位应该是X
                        if (idCardMod == 2) {
                            if (idCardLast == "X" || idCardLast == "x") {
                                flag = true;
                            } else {
                                this.$toast('身份证最后一位输入错误');
                                flag = false;
                            }
                        } else {
                            //用计算出的验证码与最后一位身份证号码匹配，如果一致，说明通过，否则是无效的身份证号码
                            if (idCardLast == idCardY[idCardMod]) {
                                flag = true;
                            } else {
                                this.$toast('请输入正确身份证号码');
                                flag = false;
                            }
                        }
                    } else if (idCard.length == 15) {
                        var id17 = idCard.substring(0, 6) + '19' + idCard.substring(6);
                        var parityBit = getParityBit(id17);
                        var tempIdCard = id17 + parityBit;
                        flag = validateIdCard(tempIdCard);
                    }
                } else {
                    this.$toast('身份证格式不正确或未填写身份证号码');
                    flag = false;
                }
                return flag;
            },
            //提交表单
            onSubmit(values) {
                if (this.validatefrom(values)) {
                    var vm = this;
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: "./kzq/tjoder.php",
                        data: {
                            goods: values.goods,
                            name: values.username,
                            uid: values.useridno,
                            phone: values.phone,
                            sf: vm.addresslist[0].name,
                            city: vm.addresslist[1].name,
                            xian: vm.addresslist[2].name,
                            dizhi: values.address,
                        },
                        ssuccess: function (data) {
                            // console.log(data);
                            // 解析服务器返回的 JSON 对象
                            var result = JSON.parse(data);
                            // 根据服务器返回的状态码弹出提示信息
                            if(result.status === 0) {
                                alert('申请成功！');
                                // 延迟1秒后跳转回上一页
                                setTimeout(function(){
                                    history.go(-1);
                                }, 1000);
                            } else if(result.status === 1) {
                                alert('您已经申请过了，无需再申请！');
                            } else {
                                alert('信息不全，请输入全部信息');
                                history.back();
                            }
                        }
                    });
                }
            },
            //选择配送地址
            onConfirm(values) {
                var vm = this;
                if (values[0]['name'] == '') {
                    this.$toast('请选择省份');
                } else if (values[1]['name'] == '') {
                    this.$toast('请选择市区');
                } else if (values[2]['name'] == '') {
                    this.$toast('请选择区域');
                } else {
                    this.userinfo.distribution = values[0]['name'] + '/' + values[1]['name'] + '/' + values[2]['name']
                    this.showArea = false;
                    this.addresslist = values;
                }
            },

        }
    });
</script>

</html>